package com.hzh.cusviewdemo.Adapter;

import android.content.Context;
import android.content.Intent;

import com.blankj.utilcode.util.TimeUtils;
import com.bumptech.glide.Glide;
import com.cbman.roundimageview.RoundImageView;
import com.hzh.cusviewdemo.Activity.LookSongMenuActivity;
import com.hzh.cusviewdemo.Activity.MusicActivity;
import com.hzh.cusviewdemo.Bean.MusicSearchData;
import com.hzh.cusviewdemo.Bean.MySongMenu;
import com.hzh.cusviewdemo.R;
import com.hzh.cusviewdemo.Util.DialogUtils;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * 歌单列表适配器
 */
public class MySongMenuAdapter extends BaseLoadMoreDataAdapter<MySongMenu> {

    public MySongMenuAdapter(Context context, List<MySongMenu> dataList) {
        super(context, dataList);
    }

    @Override
    public void bindData(BaseRecyclerViewHolder holder, int position, MySongMenu item) {
        holder.setText(R.id.ism_menu_name, item.getName());
        Date date = TimeUtils.string2Date(item.getCreateTime(), "yyyy-MM-dd HH:mm:ss");
        holder.setText(R.id.ism_menu_info, item.getNum() + "首 · " + TimeUtils.date2String(date, "MM-dd"));
        RoundImageView imageView = holder.findViewById(R.id.ism_menu_pic);
        if (item.getPic().equals("")) {
            // 空图片
            Glide.with(getContext()).load(R.drawable.ic_logo).placeholder(R.drawable.ic_logo).error(R.drawable.ic_logo).into(imageView);
        } else {
            Glide.with(getContext()).load(item.getPic()).placeholder(R.drawable.ic_logo).error(R.drawable.ic_logo).into(imageView);
        }
        holder.setOnClick(R.id.ism_linear_menu, v -> {
            Intent intent = new Intent(getContext(), LookSongMenuActivity.class);
            intent.putExtra("TAG_MENU_NAME", item.getName());
            getContext().startActivity(intent);
        });
    }

    @Override
    public int getItemLayoutId(int viewType) {
        return R.layout.item_song_menu;
    }
}
